package cn.com.yusys.yusp.custManager.web.rest;

import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import cn.com.yusys.yusp.custManager.domain.MarketCustGroup;
import cn.com.yusys.yusp.custManager.service.MarketCustGroupService;
import cn.com.yusys.yusp.custManager.service.MessageSendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: zoie
 * @Description: 营销客户群
 * @Date: 2021/5/1
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/marketCustGroup")
@Api(tags = "marketCustGroup")
public class MarketCustGroupResource {
    @Autowired
    private MarketCustGroupService marketCustGroupService;

    @Autowired
    private MessageSendService messageSendService;

    public MarketCustGroupResource(MarketCustGroupService service) {
        super();
        this.marketCustGroupService =service;
        // TODO Auto-generated constructor stub
    }
    private final Logger log = LoggerFactory.getLogger(MarketCustGroupResource.class);

    /**
     * @方法名称: getGroupList
     * @方法描述: 营销客户群
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/getGroupList")
    @ApiOperation(value = "营销客户群", notes = "营销客户群")
    public ResultDto<List<Map<String, Object>>> getGroupList(QueryModel queryModel) {
        List<Map<String, Object>> list = marketCustGroupService.getGroupList(queryModel);
        return new ResultDto<>(list);
    }

    /**
     * 更新客户群信息
     * @param marketCustGroup
     * @return
     */
    @PostMapping("/saveGroup")
    @ApiOperation(value = "修改营销客户群", notes = "修改营销客户群")
    public ResultDto<MarketCustGroup> saveGroup(@RequestBody MarketCustGroup marketCustGroup) {
        ResultDto<MarketCustGroup> resultDto = new ResultDto<>();
        try {
            MarketCustGroup result = marketCustGroupService.saveGroup(marketCustGroup);
            resultDto.setData(result);
            resultDto.setMessage("更新营销客群成功!");
        } catch (Exception e) {
            resultDto.setCode(500);
            resultDto.setMessage(e.getMessage());
        }
        return resultDto;
    }

    /**
     * 批量删除客户群组
     * @param ids
     * @return
     */
    @PostMapping("/batchDeleteGroup/{ids}")
    @ApiOperation(value = "批量删除客户群", notes = "批量删除客户群")
    public ResultDto<Integer> batchDeleteGroup(@PathVariable String ids) {
        int result = marketCustGroupService.batchDeleteGroup(ids);
        return new ResultDto<>(result);

    }

    /**
     * 删除客户群组
     * @param map
     * @return
     */
    @PostMapping("/deleteGroup")
    @ApiOperation(value = "批量删除客户群", notes = "批量删除客户群")
    public ResultDto<Integer> deleteGroup(@RequestBody Map map) {
        String id = map.get("id").toString();
        String custGroupNo = map.get("custGroupNo").toString();
        int result = marketCustGroupService.deleteGroup(id,custGroupNo);
        return new ResultDto<>(result);

    }

    /**
     * 灵活查询时创建客户群并且添加客户和客群关系
     * 一级根据机构查询网格编号（唯一），二级根据userId查询多个网格编号
     * @param t
     * @return
     */
    @PostMapping("/insertCusGroup")
    @ApiOperation(value = "创建客群", notes = "创建客群以及客户")
    public ResultDto insertCusGroup(@RequestBody Map<?, ?> t){
        marketCustGroupService.insertCusGroup(t);
        return new ResultDto();
    }

    /**
     * 客户明细
     * @param queryModel
     * @return
     */
    @GetMapping("/getCustInfo")
    @ApiOperation(value = "客户明细", notes = "客户明细")
    public ResultDto<List<Map<String, Object>>> getCustInfo(QueryModel queryModel){
        List<Map<String, Object>> list = marketCustGroupService.getCustInfo(queryModel);
        return new ResultDto<>(list);
    }

    /**
     * 短信发送模版
     * @return
     */
    @GetMapping("/selectMessageTemInfo")
    @ApiOperation(value = "短信发送模板", notes = "短信发送模板")
    public ResultDto<Map<String, Object>> queryMessageTemInfo(String modelType) {
        Map<String, Object> map = messageSendService.selectMessageTemInfo(modelType);
        return new ResultDto<>(map);
    }

    @PostMapping("/insertApprove")
    @ApiOperation(value = "短信发送", notes = "短信发送")
    public ResultDto<Integer> insertApprove(@RequestBody Map map){
        messageSendService.insertApprove(map);
        return new ResultDto<>();
    }

    @GetMapping("/getApprove")
    @ApiOperation(value = "短信发送审核人员", notes = "短信发送审核人员")
    public ResultDto<List<Map<String, Object>>> getApprove(String orgId) {
        List<Map<String, Object>> list = messageSendService.getApprove(orgId);
        return new ResultDto<>(list);
    }

    @PostMapping("/approveSendMessage")
    @ApiOperation(value = "短信发送审核", notes = "短信发送审核")
    public ResultDto<Integer> approveSendMessage(@RequestBody Map map){
        messageSendService.approveSendMessage(map);
        return new ResultDto<>();
    }



}



